<template>
	<!-- 自定义导航栏 -->
	<view >
		<uni-nav-bar left-icon="back" right-text="发布" :statusBar="true" 
		@clickLeft="back" 
		@clickRight="submit">
			<view class="u-f-ajc" @tap="changelook">
				<!-- 所有人可见 -->
				{{look}}
				<view class="icon iconfont icon-xialazhankai"></view>
			</view>
		</uni-nav-bar>
		
		<!-- 多行输入框 -->
		<view class="uni-textarea">
			<textarea v-model="text" placeholder="说一句话吧"></textarea>
		</view>
		<!-- 上传多图 -->
		<upload-images @upload="upload"></upload-images>
		
		<!-- 弹出公告 -->
		<uni-popup type="center" ref="popup">
			<view class="notice-box">
				<view class="u-f-ajc">
					<image src="../../static/common/ban.png" mode="widthFix"></image>
				</view>
				<view>1.涉及黄色，政治，广告及骚扰信息</view>
				<view>2.涉及黄色，政治，广告及骚扰信息</view>
				<view>3.涉及黄色，政治，广告及骚扰信息</view>
				<view>4.涉及黄色，政治，广告及骚扰信息</view>
				<button type="default" @tap="hidePopup">朕知道了</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import uniNavBar from '../../components/uni-nav-bar/uni-nav-bar.vue';
	import uploadImages from '../../components/common/upload-images.vue';
	import uniPopup from '../../components/uni-popup/uni-popup.vue';
	
	let changelooks = ['所有人可见','仅自己可见'];
	
	
	export default {
		components:{
			uniNavBar,
			uploadImages,
			uniPopup
		},
		data() {
			return {
				look: '所有人可见',
				text: '',
				imageList: [],
				isget: false
			}
		},
		/* 监听返回按钮 */
		onBackPress() {
			// 如果输入的有内容
			if(!this.text && this.imageList.length < 1){
				return;
			}
			// 判断是否保存
			if(!this.isget){
				this.saveDraft();
				return true;
			}
		},
		onReady() {
			this.$refs.popup.open()
		},
		methods: {
			/* 保存为草稿 */
			saveDraft(){
				uni.showModal({
					content: '是否需要保存为草稿？',
					cancelText:'不保存',
					confirmText:'保存',
					success: (res) => {
						if(res.confirm){
							// 选择保存
							console.log('保存');
						}else{
							// 不保存
							console.log('不保存');
						}
						this.isget = true;
						uni.navigateBack({
							delta:1
						});
					}
				});	
			},
			back(){
				uni.navigateBack({
					delta:1
				})
			},
			/* 发布 */
			submit(){
				
			},
			/* 隐私 */
			changelook(){
				uni.showActionSheet({
					itemList:changelooks,
					success: (res) => {
						this.look = changelooks[res.tapIndex];
					}
				})
			},
			upload(arr){
				this.imageList = arr;
			},
			hidePopup(){
				this.$refs.popup.close();
			}
		}
	}
</script>

<style>
	.uni-textarea{
		border: 1upx solid #EEEEEE;
	}
	.notice-box{
		background: #FFFFFF;
		border-radius: 20upx;
		padding: 30upx;
	}
	.notice-box image{
		width: 95%;
	}
	.notice-box button{
		background: #FFE934;
		color: #333333;
		margin: 20upx 0;
	}
</style>
